package com.bestcem.xm.ticket.enums;

import lombok.Getter;
import lombok.ToString;

/**
 * ticket ttype 枚举
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/10 17:49
 */
@Getter
@ToString
public enum TicketTypeEnum {
    /**
     * 预警
     */
    UN_NEED_DEAL("UNNEED_DEAL", 0),
    /**
     * 工单
     */
    NEED_DEAL("NEED_DEAL", 1),
    /**
     * all状态,数据库中没有存这个,只是单纯为了字符串常量
     */
    ALL("all", 100);

    private final String name;

    private final Integer index;

    TicketTypeEnum(String name, Integer index) {
        this.name = name;
        this.index = index;
    }

    /**
     * 根据 index 获取枚举实体
     * 找不到则返回 null
     *
     * @param index 枚举index
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/8/17 20:31
     */
    public static TicketTypeEnum getByIndex(Integer index) {
        for (TicketTypeEnum value : values()) {
            if (value.getIndex().equals(index)) {
                return value;
            }
        }
        return null;
    }
}
